<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an ezone
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4182 2010-08-01 16:27:10Z huuphuoc $
 * @since		2.0.0
 */
?>
<?php 
$this->headTitle($this->translator('zone_list_zone_title'));


?>
<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/article.png'; ?>" alt=""/>
    <span><?php echo $this->translate('zone_list_breadcrumb') ?></span>
    <input type="button" id="btnCreate" class="button" value="<?php echo $this->translate('zone_list_add'); ?>" onclick="location = '<?php echo $this->url(array(), 'ad_zone_add'); ?>';"/>
</div>
<table class="list" cellspacing="0">
        <thead>
            <tr>
                <td width="3%">
                        <input type="checkbox" class="chkAll"/>
                </td>
                <td width="20%">
                        <?php echo $this->translator('zone_list_name'); ?>
                </td>
                <td width="45%">
                        <?php echo $this->translator('zone_list_description'); ?>
                </td>
                <td width="15%">
                        <?php echo $this->translator('zone_list_width_height'); ?>
                </td>
                <td width="15%">
                        <?php echo $this->translate('zone_list_actions'); ?>
                </td>
            </tr>
        </thead>
        <tbody>
            <?php if (!count($this->zones)) : ?>
            <tr><td colspan ="4" style="color: #fc0202;"><?php echo $this->translator('zone_list_not_found'); ?></td></tr>
            <?php else : 
                $i=0;
            ?>
            <?php foreach ($this->zones as $zone) : ?>
            <?php
                $class= 'class="'. (($i == $this->numzones - 1) ? 'last' : '')  . '"';
            ?>
            <tr id="zone-<?php echo $zone->id?>" <?php echo $class?>>
                <td>
                    <input type="checkbox" class="chkId" value="<?php echo $zone->id;?>"/>
                </td>
                <td><?php echo $zone->name?></td>
                <td><?php echo $zone->description?></td>
                <td><b><?php echo $zone->width; ?></b> x <b><?php echo $zone->height; ?></b></td>
                <td>
                    <?php if ($this->allow('edit')) : ?>
                    <a href="<?php echo $this->url(array('id' => $zone->id), 'ad_zone_edit'); ?>"><?php echo $this->translator('zone_list_edit_action'); ?></a>
                    <?php endif; ?>

                    <?php if ($this->allow('delete')) : ?> 
                    <a href="javascript: void(0);" rel="<?php echo $zone->id; ?>" class="deleteAction"><?php echo $this->translator('zone_list_delete_action'); ?></a>
                    <?php endif; ?>
                </td>
            </tr>
            <?php $i++;?>
            <?php endforeach;?>
            <?php endif;?>
        </tbody>
        <tfoot>
            <tr>
                <td>
                        <input type="checkbox" class="chkAll"/>
                </td>
                <td>
                        <?php echo $this->translator('zone_list_name'); ?>
                </td>
                <td>
                        <?php echo $this->translator('zone_list_description'); ?>
                </td>
                <td width="15%">
                        <?php echo $this->translator('zone_list_width_height'); ?>
                </td>
                <td>
                        <?php echo $this->translate('zone_list_actions'); ?>
                </td>
            </tr>
        </tfoot>
    </table>



<script type="text/javascript">
$(document).ready(function() {
	<?php if ($this->allow('delete')) : ?>
	$('.deleteAction').click(function() {
		var self = this;
                if(confirm('<?php echo addslashes($this->translator('zone_list_delete_confirm')); ?>')){
                    $(self).html('').addClass('loading_inline');
                    var id = $(self).attr('rel');
                    $.ajax({
                            url: '<?php echo $this->url(array(), 'ad_zone_delete'); ?>',
                            type: 'POST',
                            data: { id: id },
                            dataType: 'json',
                            success: function(response) {
                                if(response.status){
                                    $('#zone-' + id).fadeOut('slow');
                                }
                            }
                    });
                }
	});
	<?php endif; ?>
});
</script>
